﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CF.Data.Entity.FrmMemberEntity;

namespace CF.Member.DAL.Member
{
    public class FM_LevelConfigDAL
    {
        public void Add(FM_LevelConfig lvlCfg)
        {
            caifendbEntities context = new caifendbEntities();
            context.AddToFM_LevelConfig(lvlCfg);
            context.SaveChanges();
        }

        public List<FM_LevelConfig> GetAllLevelCfg(int start, int limit)
        {
            List<FM_LevelConfig> lvlist = new List<FM_LevelConfig>();
            caifendbEntities context = new caifendbEntities();
            context.ContextOptions.LazyLoadingEnabled = false;
            var query = context.FM_LevelConfig.OrderBy(c => c.LID).Skip(start).Take(limit);
            lvlist = query.ToList();
            return lvlist;
        }

        public bool Update(int lid, FM_LevelConfig updLvlCfg)
        {
            bool result = false;
            caifendbEntities context = new caifendbEntities();
            FM_LevelConfig lvlCfg = context.FM_LevelConfig.FirstOrDefault(c => c.LID == lid);
            if (lvlCfg != null)
            {
                lvlCfg.LevelName = updLvlCfg.LevelName;
                lvlCfg.BeginLevel = updLvlCfg.BeginLevel;
                lvlCfg.EndLevel = updLvlCfg.EndLevel;
                lvlCfg.FirstValue = updLvlCfg.FirstValue;
                context.SaveChanges();
                result = true;
            }
            return result;
        }

        public bool Remove(int lid)
        {
            bool result = false;
            caifendbEntities context = new caifendbEntities();
            FM_LevelConfig lcfg = context.FM_LevelConfig.FirstOrDefault(c => c.LID == lid);
            if (lcfg != null)
            {
                context.DeleteObject(lcfg);
                context.SaveChanges();
                result = true;
            }
            return result;
        }

        public FM_LevelConfig GetLevelCfg(int lid)
        {
            caifendbEntities context = new caifendbEntities();
            FM_LevelConfig lcfg = context.FM_LevelConfig.FirstOrDefault(c => c.LID == lid);
            return lcfg;
        }
    }
}
